#include "upgrademenu.h"

using namespace std;

UpgradeMenu::UpgradeMenu(bool farm, bool mine, bool cottage, int x, int y):BaseWidget(x, y, 50, 150, false){
    btnFarm = new Button(0, 0, 50, 50, 0);
    btnFarm->SetMessageOnLeftMouseDown(new Message(GXM_BUILD_FARM));
    btnFarm->name = "F";
    btnCottage = new Button(0, 50, 50, 50, 0);
    btnCottage->SetMessageOnLeftMouseDown(new Message(GXM_BUILD_TOWN));
    btnCottage->name = "T";
    btnMine = new Button(0, 100, 50, 50, 0);
    btnMine->SetMessageOnLeftMouseDown(new Message(GXM_BUILD_MINE));
    btnMine->name = "M";

    this->AddChild(btnFarm);
    this->AddChild(btnCottage);
    this->AddChild(btnMine);
}

void UpgradeMenu::Draw(){
    if(!hidden){
        glPushMatrix();
        glTranslatef(x, y, 0);
        glColor3f(0, 0.5, 0.5);
        glBegin(GL_QUADS);
        glVertex3f(0, 0, 0);
        glVertex3f(width, 0, 0);
        glVertex3f(width, height, 0);
        glVertex3f(0, height, 0);
        glEnd();

        glPopMatrix();

        BaseWidget::Draw();
    }
}

void UpgradeMenu::ProcessMessages(){
    for(int i=0;i<children.size();i++){
        children[i]->ProcessMessages();
    }

//    for(int i=0;i<messageQueue.size();i++){
//        if(messageQueue.front()->type == GXM_CLOSE){
//            cout<<"Message == GXM_CLOSE"<<endl;
//            hidden = true;
//            messageQueue.pop();
//        }
//        else{
//            messageQueue.push(messageQueue.front());
//            messageQueue.pop();
//        }
//    }
    while(!messageQueue.empty()){
        if(parent != 0){
            PostMessage(messageQueue.front());
        }
        messageQueue.pop();
    }
}

